package org.tp.framework.util;

import com.google.gson.Gson;

public class JsonUtils {
    private static Gson gson;

    static {
        gson = new Gson();
    }

    public static String objToStr(Object object) {
        if (object == null) {
            return null;
        }
        return gson.toJson(object);
    }

    @SuppressWarnings("unchecked")
    public static <T> T strToObj(String json, Class<?> clazz) {
        return (T) gson.fromJson(json, clazz);
    }
}
